package com.ll.domain.jj.base.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ll.app.api.jj.AddJJClassDTO;
import com.ll.app.api.jj.PageJJClassReqDTO;
import com.ll.base.dto.PageResultDTO;
import com.ll.base.util.ListUtil;
import com.ll.base.util.ScalarUtil;
import com.ll.dal.mapper.ClassBaseMapper;
import com.ll.dal.mapper.JJClassMapper;
import com.ll.dal.po.JJClassPO;
import com.ll.dal.po.RankingPO;
import com.ll.domain.jj.base.JJClassBaseService;
import com.ll.domain.ranking.convert.RankingConvert;
import com.ll.domain.ranking.dto.RankingDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 班级服务
 *
 * @author WuHen
 * @date 2021/10/16 17:54
 **/
@Service
@RequiredArgsConstructor
public class JJClassBaseServiceImpl extends ServiceImpl<JJClassMapper, JJClassPO> implements JJClassBaseService {

    private final JJClassMapper jjClassMapper;
    @Override
    public PageResultDTO<JJClassPO> page(PageJJClassReqDTO req) {
        req.initPage();
        IPage<JJClassPO> iPage = new Page<JJClassPO>(req.getPageNo(), req.getPageSize());
        iPage = jjClassMapper.selectPage(iPage, new LambdaQueryWrapper<JJClassPO>()
                .eq(ScalarUtil.isNotEmpty(req.getCDingUid()) , JJClassPO::getCDingUid, req.getCDingUid())
                .orderByDesc(JJClassPO::getCtime)
        );
        return new PageResultDTO<JJClassPO>(iPage.getRecords(), iPage.getTotal(), req);
    }

    @Override
    public boolean add(AddJJClassDTO dto) {
        JJClassPO po = new JJClassPO();
        BeanUtils.copyProperties(dto, po);
        po.setCtime(new Date());
        return jjClassMapper.insert(po) > 0;
    }

}
